$(function () {
    Time();
    load();
})

//返回
function fh() {
    localStorage.removeItem("chaSH_ID");
    location.href = "../../li_meng/CPSCGXShengHe.html";
}

//时间
function Time() {
    var time = new Date();
    var y = time.getFullYear();
    var mon = time.getMonth() + 1; //0-11
    var d = time.getDate();
    var h = time.getHours();
    var m = time.getMinutes();
    var s = time.getSeconds();
    $("#date").val(y + "-" + mon + "-" + d + " " + h + ":" + m + ":" + s);
}

//表单
function load() {
    let user = JSON.parse(localStorage.getItem("user"));
    $("#rname").val(user.rname);
    let MdeSH = JSON.parse(localStorage.getItem("MdeSH"));
    //设计单编号
    $("#designid").text(MdeSH.designid);
    //设计人
    $("#designer").text(MdeSH.designer);
    //产品编号
    $("#productid").text(MdeSH.productid);
    //产品名称
    $("#productname").text(MdeSH.productname);
    //总工时
    $("#costpricesum").text(MdeSH.costpricesum);
    //设计要求
    $("#proceduredescribe").val(MdeSH.proceduredescribe);

    $.post("/Mdesignproceduredetails.do/ChaById", {id:MdeSH.id}, function (sdata) {
        let str = " <tr >\n" +
            "           <th>序号</th>\n" +
            "           <th>工序名称</th>\n" +
            "           <th>工序编号</th>\n" +
            "           <th>描述</th>\n" +
            "           <th>工时数</th>\n" +
            "           <th>单位</th>\n" +
            "           <th>单位工时成本</th>\n" +
            "           <th>工时成本小计(元)</th>\n" +
            "       </tr>\n";

        $.each(sdata, function (index, item) {
            str +=
                "  <tr>\n" +
                "      <td>" + item.id + "</td>\n" +
                "      <td>" + item.procedurename + "</td>\n" +
                "      <td>" + item.procedureid + "</td>\n" +
                "      <td>" + item.proceduredescribe + "</td>\n" +
                "      <td>" + item.labourhouramount + "</td>\n" +
                "      <td>h</td>\n" +
                "      <td>" + item.costprice + "</td>\n" +
                "      <td>"+item.subtotal+"</td>\n" +
                "  </tr>";
        })
        $("#tableAdd").html(str);
    })
}

//提交数据
function Submit() {
    let MdeSH = JSON.parse(localStorage.getItem("MdeSH"));
    let mdesignprocedure = {
        checktag:$("[name='zt']:checked").val(),
        checker:$("#rname").val(),
        checktime:$("#date").val(),
        checksuggestion:$("#proceduredescribe").val(),
        id:MdeSH.id};
    let mdList = JSON.stringify(mdesignprocedure);
    $.post("/Mdesignprocedure.do/upBySHBZ",{mdList:mdList,dfID:MdeSH.productid},function (sd) {
        $("#tishi").text("提交审核成功！")
        $("#tishi").css("color","lime")
        $("#staticBackdrop").modal("show");
    })
}

//提交后跳页面
function hh() {
    location.href = "../../li_meng/CPSCGXShengHe.html";
}